home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRICMP.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  109 lines

  1. StdGrp        group    StdLib, StdData
  2. ;
  3. StdData        segment    para public 'sldata'
  4.         extrn    $uprtbl:byte
  5. StdData        ends
  6. ;
  7. stdlib        segment    para public 'slcode'
  8.         assume    cs:StdGrp
  9. ;
  10. ;
  11. ; stricmp- Compares two strings, ignoring differences in case.
  12. ;
  13. ; inputs:
  14. ;
  15. ;    es:di-    First string (The string to compare)
  16. ;    dx:si-    Second string (The string to compare against)
  17. ;
  18. ;    e.g.,
  19. ;        "if (es:di < dx:si) then ..."
  20. ;
  21. ; returns: 
  22. ;
  23. ;    cx- index into strings where they differ (points at the zero byte
  24. ;        if the two strings are equal).
  25. ;    Condition codes set according to the string comparison.  You should
  26. ;    use the unsigned branches (ja, jb, je, etc.) after calling this
  27. ;    routine.
  28. ;
  29.         public    sl_stricmp
  30. ;
  31. sl_stricmp    proc    far
  32.         push    es
  33.         push    ds
  34.         push    bx
  35.         push    ax
  36.         push    si
  37.         push    di
  38.         xchg    di, si
  39.         mov    ax, es
  40.         mov    ds, ax
  41.         mov    es, dx
  42.         xor    cx, cx        ;Set initial index to zero.
  43.         lea    bx, stdgrp:$uprtbl
  44. ;
  45. ; In order to preserve the direction flag across this call, we have to
  46. ; test whether or not it is set here and execute two completely separate
  47. ; pieces of code (so we know which state to exit in.  Unfortunately, we
  48. ; cannot use pushf to preserve this flag since we need to return status
  49. ; info in the other flags.
  50. ;
  51.         pushf
  52.         pop    ax
  53.         test    ah, 4        ;Test direction bit.
  54.         jnz    DirIsSet
  55. sclp:        lodsb
  56.         xlat    StdGrp:$uprtbl
  57.         mov    ah, al
  58.         mov    al, es:[di]
  59.         xlat    StdGrp:$uprtbl
  60.         cmp    ah, al        
  61.         jne    scNE        ;If strings are <>, quit.
  62.         inc    cx            ;Increment index into strs.
  63.         inc    di        ;Incrment str2 ptr.
  64.         cmp    al, 0        ;Check for end of strings.
  65.         jne    sclp
  66.         pushf
  67.         dec    cx
  68.         popf
  69. ;
  70. scNE:        pop    di
  71.         pop    si
  72.         pop    ax
  73.         pop    bx
  74.         pop    ds
  75.         pop    es
  76.         ret            ;Return with direction flag clear.
  77. ;
  78. ;
  79. DirIsSet:    lodsb
  80.         xlat    StdGrp:$uprtbl
  81.         mov    ah, al
  82.         mov    al, es:[di]
  83.         xlat    StdGrp:$uprtbl
  84.         cmp    ah, al
  85.         jne    scNE2         ;If strings are <>, quit.
  86.         inc    cx
  87.         inc    di
  88.         cmp    al, 0         ;Check for end of strings.
  89.         jne    DirIsSet
  90.         pushf
  91.         dec    cx
  92.         popf
  93. ;
  94. scNE2:        pop    di
  95.         pop    si
  96.         pop    ax
  97.         pop    bx
  98.         pop    ds
  99.         pop    es
  100.         std            ;Return with direction flag set.
  101.                 ret
  102.  
  103. sl_stricmp    endp
  104. ;
  105. ;
  106. stdlib        ends
  107.         end
  108.